
<template>
  <div class="app-container">
<!--    <el-form :inline="true" :model="queryParams" label-width="120px" ref="queryForm">-->
<!--      <el-form-item label="led屏的ip地址" prop="ipled">-->
<!--        <el-input-->
<!--          @keyup.enter.native="handleQuery"-->
<!--          clearable-->
<!--          placeholder="请输入led屏的ip地址"-->
<!--          size="small"-->
<!--          v-model="queryParams.ipled"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item>-->
<!--        <el-button @click="handleQuery" icon="el-icon-search" size="mini" type="primary">搜索</el-button>-->
<!--        <el-button @click="resetQuery" icon="el-icon-refresh" size="mini">重置</el-button>-->
<!--      </el-form-item>-->
<!--    </el-form>-->
    <el-form :inline="true" :model="queryParams" label-width="120px" ref="queryForm">
      <el-form-item label="设备名称" prop="remark">
        <el-input
          @keyup.enter.native="handleQuery"
          clearable
          placeholder="请输入设备名称"
          size="small"
          v-model="queryParams.remark"
        />
      </el-form-item>
      <el-form-item label="led屏的ip地址" prop="ip">
        <el-input
          @keyup.enter.native="handleQuery"
          clearable
          placeholder="请输入led屏的ip地址"
          size="small"
          v-model="queryParams.ip"
        />
      </el-form-item>
      <el-form-item>
        <el-button @click="handleQuery" icon="el-icon-search" size="mini" type="primary">搜索</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          @click="handleAdd"
          icon="el-icon-plus"
          size="mini"
          type="primary"
          v-hasPermi="['lgdz:led:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          @click="handleExport"
          icon="el-icon-download"
          size="mini"
          type="warning"
          v-hasPermi="['lgdz:led:export']"
        >导出
        </el-button>
      </el-col>
    </el-row>
    <el-table :data="ledList" @selection-change="handleSelectionChange">
      <el-table-column align="center" sortable label="led表主键" prop="id" width="160" />
      <el-table-column align="center" label="led屏的ip地址" prop="ip" width="140" />
      <el-table-column align="center" label="led屏总宽度" prop="totalwidth" width="140" />
      <el-table-column align="center" label="led屏总高度" prop="totalheight" width="140" />
      <el-table-column align="center" label="led屏类型" prop="ledtype" width="140">
        <template
          slot-scope="scope"
        >{{scope.row.ledtype=="1"?"晟浩全彩屏":scope.row.colortype=="2"?"灵信CM":"灵信T4"}}</template>
      </el-table-column>
      <el-table-column align="center" label="led屏颜色" prop="colortype" width="140">
        <template
          slot-scope="scope"
        >{{scope.row.colortype=="1"?"单色":scope.row.colortype=="2"?"双基色":scope.row.colortype=="3"?"三基色":''}}</template>
      </el-table-column>
      <el-table-column align="center" label="创建时间" prop="createtime">
        <!-- <template slot-scope="scope">
        <span>{{ parseTime(scope.row.createtime, '{y}-{m}-{d}')}}</span>
        </template>-->
      </el-table-column>
      <el-table-column align="center" label="设备名称" prop="remark" />
      <el-table-column align="center" class-name="small-padding fixed-width" label="操作">
        <template slot-scope="scope">
          <el-button @click="handleUpdate(scope.row)" size="mini" type="text">修改</el-button>
<!--          <el-button-->
<!--            v-if="scope.row.ledtype == '3'"-->
<!--            @click="jiaoyan(scope.row)"-->
<!--            size="mini"-->
<!--            type="text"-->
<!--          >校验时间</el-button>-->
<!--          <el-button-->
<!--            v-if="scope.row.ledtype == '3'"-->
<!--            @click="ceshileds(scope.row)"-->
<!--            size="mini"-->
<!--            type="text"-->
<!--          >测试LED</el-button>-->
          <el-button @click="handleDelete(scope.row)" size="mini" type="text">删除</el-button>
          <!-- <el-button @click="time(scope.row)" icon="el-icon-edit" size="mini" type="text">同步时间</el-button> -->
          <el-switch
            style="display: block"
            v-model="scope.row.ledenable"
            active-color="#13ce66"
            inactive-color="#ff4949"
            @change="switcy($event, scope.row.id, scope.$index)"
            active-text="开"
            inactive-text="关"
          ></el-switch>
        </template>
      </el-table-column>
    </el-table>
    <!--    <pagination-->
    <!--      :limit.sync="queryParams.pageSize"-->
    <!--      :page.sync="queryParams.pageNum"-->
    <!--      :total="total"-->
    <!--      @pagination="getList"-->
    <!--      v-show="total>0"-->
    <!--    />-->

    <!-- 修改led屏对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      append-to-body
      width="1000px"
    >
      <el-form label-width="120px" ref="formData" :rules="rules" size="small">
        <div class="item-top">
          <el-row>
            <el-col :span="8">
              <el-form-item label="设备名称" prop="remark">
                <el-input
                  :style="{ width: '100%' }"
                  clearable
                  placeholder="请输入设备名称"
                  v-model="formData.remark"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="设备序列号" prop="ledserialno">
                <el-input
                  :style="{ width: '100%' }"
                  clearable
                  placeholder="请输入设备序列号"
                  v-model="formData.ledserialno"
                  :disabled="true"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="IP地址" prop="ip">
                <el-input
                  :style="{ width: '100%' }"
                  clearable
                  placeholder="请输入IP地址"
                  v-model="formData.ip"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-col :span="8">
            <el-form-item label="LED屏幕总宽度" prop="totalwidth ">
              <el-input
                :style="{ width: '100%' }"
                @blur="totalwidth($event)"
                clearable
                placeholder="请输入LED屏幕总宽度"
                v-model="formData.totalwidth"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="LED屏幕总高度" prop="totalheight">
              <el-input
                :style="{ width: '100%' }"
                @blur="hei($event)"
                clearable
                placeholder="请输入LED屏幕总高度"
                v-model="formData.totalheight"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="LED屏颜色">
              <el-select  :style="{ width: '100%' }" v-model="formData.colortype" placeholder="请选择LED屏颜色">
                <el-option label="单色" value="1"></el-option>
                <el-option label="双基色" value="2"></el-option>
                <el-option label="三基色" value="3"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="LED屏类型">
              <el-select
                :disabled="true"
                :style="{ width: '100%' }"
                @change="bclxChange"
                v-model="formData.ledtype"
                placeholder="请选择LED屏类型"
              >
                <el-option label="晟浩全彩屏" value="1"></el-option>
                <el-option label="灵信CM4" value="2"></el-option>
                <el-option label="灵信T4" value="3"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </div>
        <!--        添加部分-->
        <!-- <div class="item-center" v-for="(item,index) in itemArr" :key="index">-->
        <div :key="index"
             class="item-center"
             v-for="(item, index) in itemArr"
             style="margin-top: 10px"
        >
          <div v-if="isJxBc">
            <el-col :span="8">
              <el-form-item label="区域编号">
                <el-input
                  :style="{ width: '100%' }"
                  clearable
                  placeholder="请输入区域编号"
                  v-model="item.region_abscissa"
                  oninput="value=value.replace(/[^\d]/g,'')"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="字体颜色">
                <el-select v-model="item.region_ordinate" placeholder="请选择字体颜色">
                  <el-option label="红色" value="1">红色</el-option>
                  <el-option label="绿色" value="2">绿色</el-option>
                  <el-option label="黄色" value="3">黄色</el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </div>
          <div v-else>
            <el-col :span="8">
              <el-form-item label="左上角横坐标" prop="region_abscissa">
                <el-input
                  :style="{ width: '100%' }"
                  clearable
                  placeholder="请输入左上角横坐标"
                  v-model="item.region_abscissa"
                  oninput="value=value.replace(/[^\d]/g,'')"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="左上角纵坐标" prop="region_ordinate">
                <el-input
                  :style="{ width: '100%' }"
                  clearable
                  placeholder="请输入左上角纵坐标"
                  v-model="item.region_ordinate"
                  oninput="value=value.replace(/[^\d]/g,'')"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="区域类型" prop="area_type">
                <el-select
                  :style="{ width: '100%' }"
                  @change="openselset(item.area_type)"
                  clearable
                  placeholder="请选择区域类型"
                  v-model="item.area_type"
                >
<!--                  <el-option-->
<!--                    :disabled="item.disabled"-->
<!--                    :key="index"-->
<!--                    :label="item.label"-->
<!--                    :value="item.value"-->
<!--                    v-for="(item, index) in area_typeOptions"-->
<!--                  ></el-option>-->
                  <el-option label="静态文本" value="0"></el-option>
                  <el-option label="多行文本" value="1"></el-option>
                  <el-option label="时间" value="2"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </div>

          <el-col :span="8">
            <el-form-item label="区域宽度">
              <el-input
                :style="{ width: '100%' }"
                @blur="validScore($event)"
                clearable
                placeholder="请输入区域宽度"
                v-model="item.regionwidth"
                oninput="value=value.replace(/[^\d]/g,'')"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="区域高度" prop="region_height">
              <el-input
                :style="{ width: '100%' }"
                @blur="qug($event)"
                clearable
                placeholder="请输入区域高度"
                v-model="item.regionheight"
                oninput="value=value.replace(/[^\d]/g,'')"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="字体大小" prop="fontsize">
              <el-input
                :style="{ width: '100%' }"
                clearable
                placeholder="请输入字体大小"
                v-model="item.fontsize"
              ></el-input>
            </el-form-item>
          </el-col>

          <el-row>
            <el-col :span="8">
              <el-form-item id="wenben" label="下发文本" prop="addstr">
                <el-input
                  :autosize="{ minRows: 2, maxRows: 2 }"
                  :style="{ width: '100%' }"
                  placeholder="请输入下发文本"
                  type="textarea"
                  v-model="item.addstr"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="数据类型" prop="datatype">
                <el-select
                  :style="{ width: '100%' }"
                  @change="openselset(item.datatype)"
                  clearable
                  placeholder="请选择数据类型"
                  v-model="item.datatype"
                >
<!--                  <el-option-->
<!--                    :disabled="item.disabled"-->
<!--                    :key="index"-->
<!--                    :label="item.label"-->
<!--                    :value="item.value"-->
<!--                    v-for="(item, index) in area_typeyy"-->
<!--                  ></el-option>-->
                  <el-option label="默认" value="1"></el-option>
                  <el-option label="在场人数" value="2"></el-option>
                  <el-option label="进出记录" value="3"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <div style="float:right;marginBottom:5px">
              <el-button @click="addDomain(item.area_type, index)" style="margin-left: 20px">新增</el-button>
              <el-button @click="deleteEle(index)">删除</el-button>
            </div>
          </el-row>
        </div>
      </el-form>
      <div class="dialog-footer" slot="footer">
        <el-button @click="xiafa" type="info">下发</el-button>
        <el-button @click="submitForm" type="primary">确 定</el-button>
        <el-button @click="cancelss">取 消</el-button>
      </div>
    </el-dialog>
<!--    添加-->
    <el-dialog
      :title="title"
      :visible.sync="opens"
      append-to-body
      width="1000px"
    >
      <el-form :rules="rules" label-width="120px" :model="formData" ref="formData" size="small">
        <div class="item-top">
          <el-row>
            <el-col :span="8">
              <el-form-item label="设备名称" prop="remark">
                <el-input
                  :style="{ width: '100%' }"
                  clearable
                  placeholder="请输入设备名称"
                  v-model="formData.remark"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="设备序列号" prop="ledserialno">
                <el-input
                  :style="{ width: '100%' }"
                  clearable
                  placeholder="请输入设备序列号"
                  v-model="formData.ledserialno"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="IP地址" prop="ip">
                <el-input
                  :style="{ width: '100%' }"
                  clearable
                  placeholder="请输入IP地址"
                  v-model="formData.ip"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-col :span="8">
            <el-form-item label="LED屏幕总宽度" prop="totalwidth ">
              <el-input
                :style="{ width: '100%' }"
                @blur="totalwidth($event)"
                clearable
                placeholder="请输入LED屏幕总宽度"
                v-model="formData.totalwidth"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="LED屏幕总高度" prop="totalheight">
              <el-input
                :style="{ width: '100%' }"
                @blur="hei($event)"
                clearable
                placeholder="请输入LED屏幕总高度"
                v-model="formData.totalheight"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="LED屏颜色">
              <el-select v-model="formData.colortype" placeholder="请选择LED屏颜色" style="width: 100%">
                <el-option label="单色" value="1"></el-option>
                <el-option label="双基色" value="2"></el-option>
                <el-option label="三基色" value="3"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="LED屏类型">
              <el-select @change="bclxChange" v-model="formData.ledtype" placeholder="请选择LED屏类型" style="width: 100%">
                <el-option label="晟浩全彩屏" value="1">晟浩全彩屏</el-option>
                <el-option label="灵信CM4" value="2">灵信CM4</el-option>
                <el-option label="灵信T4" value="3">灵信T4</el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </div>
        <!--        添加部分-->
        <!--        <div class="item-center" v-for="(item,index) in itemArr" :key="index">-->
        <div :key="index" class="item-center" v-for="(item, index) in itemArr">
          <div v-if="isJxBc">
            <el-col :span="8">
              <el-form-item label="区域编号">
                <el-input
                  :style="{ width: '100%' }"
                  clearable
                  placeholder="请输入区域编号"
                  v-model="item.region_abscissa"
                  oninput="value=value.replace(/[^\d]/g,'')"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="字体颜色">
                <el-select v-model="item.region_ordinate" placeholder="请选择字体颜色" style="width: 100%">
<!--                  <el-option-->
<!--                    :disabled="item.disabled"-->
<!--                    :key="index"-->
<!--                    :label="item.value"-->
<!--                    :value="item.fieldcode"-->
<!--                    v-for="(item, index) in fontcolor"-->
<!--                  ></el-option>-->
                  <el-option label="红色" value="1"></el-option>
                  <el-option label="绿色" value="2"></el-option>
                  <el-option label="黄色" value="3"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </div>
          <div v-else>
            <el-col :span="8">
              <el-form-item label="左上角横坐标" prop="region_abscissa">
                <el-input
                  :style="{ width: '100%' }"
                  clearable
                  placeholder="请输入左上角横坐标"
                  v-model="item.region_abscissa"
                  oninput="value=value.replace(/[^\d]/g,'')"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="左上角纵坐标" prop="region_ordinate">
                <el-input
                  :style="{ width: '100%' }"
                  clearable
                  placeholder="请输入左上角纵坐标"
                  v-model="item.region_ordinate"
                  oninput="value=value.replace(/[^\d]/g,'')"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="区域类型" prop="area_type">
                <el-select
                  :style="{ width: '100%' }"
                  @change="openselset(item.area_type)"
                  clearable
                  placeholder="请选择区域类型"
                  v-model="item.area_type"
                >
                  <el-option
                    :disabled="item.disabled"
                    :key="index"
                    :label="item.label"
                    :value="item.value"
                    v-for="(item, index) in area_typeOptions"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </div>

          <el-col :span="8">
            <el-form-item label="区域宽度">
              <el-input
                :style="{ width: '100%' }"
                @blur="validScore($event)"
                clearable
                placeholder="请输入区域宽度"
                v-model="item.regionwidth"
                oninput="value=value.replace(/[^\d]/g,'')"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="区域高度" prop="region_height">
              <el-input
                :style="{ width: '100%' }"
                @blur="qug($event)"
                clearable
                placeholder="请输入区域高度"
                v-model="item.regionheight"
                oninput="value=value.replace(/[^\d]/g,'')"
              ></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="字体大小" prop="fontsize">
              <el-input
                :style="{ width: '100%' }"
                clearable
                placeholder="请输入字体大小"
                v-model="item.fontsize"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-row>
            <el-col :span="8">
              <el-form-item id="wenben" label="下发文本" prop="addstr">
                <el-input
                  :autosize="{ minRows: 2, maxRows: 2 }"
                  :style="{ width: '100%' }"
                  placeholder="请输入下发文本"
                  type="textarea"
                  v-model="item.addstr"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="数据类型" prop="datatype">
                <el-select
                  :style="{ width: '100%' }"
                  @change="openselset(item.datatype)"
                  clearable
                  placeholder="请选择数据类型"
                  v-model="item.datatype"
                >
                  <el-option
                    :disabled="item.disabled"
                    :key="index"
                    :label="item.label"
                    :value="item.value"
                    v-for="(item, index) in area_typeyy"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <div style="float:right;marginBottom:5px">
              <el-button @click="addDomain(item.area_type, index)" style="margin-left: 20px">新增</el-button>
              <el-button @click="deleteEle(index)">删除</el-button>
            </div>
          </el-row>
        </div>
      </el-form>
      <div class="dialog-footer" slot="footer">
        <el-button @click="xiafa" type="info">下发</el-button>
        <el-button @click="submitForms" type="primary">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { delLed, exportLed, getLed, insertLedandSubLed, listLed, updateLed, uploadKai } from '@/api/lgdz/led'

  export default {
    name: 'Led',
    components: {},
    props: [],
    data() {
      return {
        dynamicValidateForm: {
          domains: [{
            value: ''
          }]
        },
        ww: '',
        hh: '',
        isJxBc: false,
        itemArr: [
          {
            region_abscissa: "",
            region_ordinate: "",
            regionwidth: "",
            regionheight: "",
            datatype: "",
            area_type: "",
            fontsize: 9,
            addstr: "",
          },
        ],
        area_typeyy: [
          {
            label: "默认",
            value: 1,
          },
          {
            label: "在场人数",
            value: 2,
          },
          {
            label: "进出记录",
            value: 3,
          }
        ],
        status: '',
        // 遮罩层
        loading: false,
        // 选中数组
        ids: [],
        //集合
        jihe: [],

        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 总条数
        total: 0,
        // led屏表格数据
        ledList: [],
        // 弹出层标题
        title: '',
        opens: false,
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          id: '',
          remark: '',
          ipled: undefined
        },
        formData: {
          ip: "",
          totalwidth: "",
          totalheight: "",
          remark: "",
          ledserialno: "",
          colortype: "",
          ledtype: "",
        },
        cc: '',
        // 表单参数
        form: {},
        rules: {
          ip: [{
            required: true,
            message: '请输入IP地址',
            trigger: 'blur'
          }]
        },
        area_typeOptions: [{
          'label': '静态文件',
          'value': 0
        }, {
          'label': '多行文本',
          'value': 1
        }, {
          'label': '时间',
          'value': 2
        }],
        // 表单校验
        rules: {}
      }
    },
    created() {
      this.getList()
    },
    methods: {
      // 根据选择框 显示隐藏元素
      bclxChange(selectValue) {
        // console.log(selectValue);
        if (selectValue == "1") {
          this.isJxBc = true;
        } else {
          this.isJxBc = false;
        }
      },
      // 开关
      switcy(event, id, index) {
        console.log(event, id, index)
        this.status = event
        // const data = {
        //   id: id * 1,
        //   ledstatus: this.status
        // }
        const api = "http://192.168.10.175:8088//led/updateLedStatus";
        this.$axios({
          url: api,
          method: "post",
          //用于表示用户代理是否在跨域请求的情况下从其他域中发送cookies
          withCredentials: true,//默认为false
          data:{
              id:id * 1,
            ledenable:this.status
          }
        }).then(res => {
          this.ledList = res.data.data
        });
        // uploadKai(data).then(response => {
        //   console.log(response)
        //   if (response.flag === true) {
        //     this.msgSuccess(response.msg)
        //   }
        // })

      },
      openselset(val,index) {
        console.log(val,index)
        let taizhang = document.getElementById('wenben')
        if (val == 2 && index == 0) {   //判断是否为第一个并且已选择了时间类型
          taizhang.style.display = 'none'   //隐藏文本
          this.area_typeOptions.splice(2)   //删除时间元素
        }
        if (val == 2 && index > 0) {
          alert('请在第一条添加时间')
          this.deleteEle()
          taizhang.style.display = 'none'
          this.area_typeOptions.splice(2)   //删除时间元素
        }
      },
      addDomain(val, index) {
        // console.log(val, index)
        this.itemArr.push({
          region_ordinate: '',
          region_abscissa: '',
          regionwidth: '',
          datatype: '',
          regionheight: '',
          area_type: '',
          fontsize: 9,
          addstr: ''
        })
      },
      deleteEle(index) {
        // console.log(index)
        if (index == 0) {
          this.$message({
            message: '第一条不能删除',
            type: 'warning'
          })
          return
        }
        this.itemArr.splice(index, 1)
      },
      totalwidth(event) {
        // console.log(event.target.value)
        this.ww = event.target.value
        // console.log(this.ww)
      },
      validScore(event) {
        // console.log(event.target.value)
        // if (event.target.value * 1 > this.ww * 1) {
        //   this.$message.error('不能超过屏幕总宽度')
        // }
      },
      hei(event) {
        // console.log(event.target.value)
        this.hh = event.target.value
      },
      qug(event) {
        // if (event.target.value * 1 > this.hh * 1) {
        //   this.$message.error('不能超过屏幕总高度')
        // }
      },
      /** 查询led屏列表 */
      getList() {
        // this.loading = true
        // listLed(this.queryParams).then(response => {
        //   console.log(response)
        //   if (response.flag == false) {
        //     this.loading = false
        //   }
        //   // console.log(response.result.length)
        //   for (var i = 0; i < response.result.length; i++) {
        //     this.jihe.push(response.result[i].child)
        //     console.log(response.result[i].ledstatus)
        //
        //   }
        //   this.ledList = response.result
        //   this.ledList.forEach(item => {
        //     if (item.ledstatus == 'true') {
        //       item.ledstatus = true
        //     }
        //     if (item.ledstatus == 'false') {
        //       item.ledstatus = false
        //     }
        //
        //   })
        //   this.loading = false
        // })
        const api = "http://192.168.10.175:8088/led/selectLed";
        this.$axios({
          url: api,
          method: "get",
          //用于表示用户代理是否在跨域请求的情况下从其他域中发送cookies
          withCredentials: true,//默认为false

        }).then(res => {
          // console.log("----------测试-----------")
          // console.log(res)
          this.ledList = res.data.data
          console.log(this.ledList)
          if (this.ledList==undefined){

          }else {
          this.ledList.forEach((item) => {
            if (item.ledenable == "true") {
              item.ledenable = true;
            }
            if (item.ledenable == "false") {
              item.ledenable = false;
            }
          });
          }
          // this.ledList.forEach((item) => {
          //   if (item.ledenable == "true") {
          //     item.ledenable = true;
          //   }
          //   if (item.ledenable == "false") {
          //     item.ledenable = false;
          //   }
          // });
        });
      },

      // 取消按钮
      cancel() {
        this.opens = false
        this.reset()
      },
      cancelss() {
        this.open = false
      },
      // 表单重置
      reset() {
        this.form = {
          id: undefined,
          ipled: undefined,
          totalwidth: undefined,
          totalheight: undefined,
          createtime: undefined,
          remark: undefined
        }
        this.resetForm('form')
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1
        this.getList()
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm('queryForm')
        this.handleQuery()
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length != 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.formData={
          ip: "",
            totalwidth: "",
            totalheight: "",
            remark: "",
            ledserialno: "",
            colortype: "",
            ledtype: "",
        },
          this.itemArr = [{
            region_abscissa: '',
            region_ordinate: '',
            regionwidth: '',
            regionheight: '',
            datatype: '',
            area_type: '',
            fontsize: 9,
            addstr: ''
          }],
          this.opens = true
        this.title = '添加LED屏'
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        // console.log(row)
        this.reset()
        const id = row.id || this.ids
        this.open = true
        this.title = '修改led屏'
        // console.log(row.ledstatus)
        const api = 'http://192.168.10.175:8088/led/queryLedAndSubById'
        this.$axios({
          url: api,
          method: 'get',
          params:{
              id:id
          }
        }).then(res => {
          // console.log(res)
          this.itemArr = res.data.result[0].child
          this.formData = res.data.result[0]
          this.open = true;
          // console.log(this.formData)

        })

        // getLed(id).then(response => {
        //   console.log(response)
        //   this.itemArr = response.result[0].child
          // this.itemArr.forEach(item => {
          //   if (item.area_type ==2) {
          //     item.area_type = "时间"
          //   }
          //   if (item.area_type ==1) {
          //     item.area_type = "静态文本"
          //   }
          //   if (item.area_type ==1) {
          //     item.area_type = "多行文本"
          //   }
          // })
          // this.formData = response.result[0]
          // console.log(this.formData)

        // })
      },

      /** 修改提交按钮 */
      submitForm: function() {
        // console.log(this.formData.id)
        var wd = parseInt(this.formData.totalwidth)
        var hg = parseInt(this.formData.totalheight)
        const api = 'http://192.168.10.175:8088/led/updateLedAndSub'
        this.$axios({
          url: api,
          method: 'post',
          data:{
            remark: this.formData.remark,
            ledserialno: this.formData.ledserialno,
            ip: this.formData.ip,
            id: this.formData.id,
            totalwidth: wd,
            totalheight: hg,
            list: this.itemArr,
            colortype: this.formData.colortype,
            ledtype: this.formData.ledtype,
          }
        }).then(res => {
          // console.log(res)
          if(res.data.flag==true){
            this.$message.success(res.data.msg)
            this.open=false
            this.getList()
          }
          if (res.data.flag!=true){
            this.$message.error(res.data.msg)
          }
        })

      },
      xiafa() {
        var wd = parseInt(this.formData.totalwidth)
        var hg = parseInt(this.formData.totalheight)
        // TODO 提交表单
        const api = 'http://192.168.10.175:8000/led/IssueLed'
        this.$axios({
          url: api,
          method: 'post',
          headers: {
            'Content-Type': 'application/json'
          },
          data: {
            ip: this.formData.ip,
            totalwidth: wd,
            totalheight: hg,
            // time: this.formData.time,
            list: this.itemArr
          }

        }).then(res => {
          // console.log(res)
          if (res.data.flag == true) {
            this.$message({
              message: '下发成功',
              type: 'success'
            })
          }
        })
      },
      // 点击新增弹窗确定
      submitForms() {
        var wd = parseInt(this.formData.totalwidth)
        var hg = parseInt(this.formData.totalheight)

        // TODO 提交表单
        const datada = {
          remark: this.formData.remark,
          ledserialno: this.formData.ledserialno,
          ip: this.formData.ip,
          totalwidth: wd,
          totalheight: hg,
          list: this.itemArr,
          colortype: this.formData.colortype,
          ledtype: this.formData.ledtype,
        }

          const api = "http://192.168.10.175:8088/led/insertLedandSub";
          this.$axios({
            url: api,
            method: "post",
            //用于表示用户代理是否在跨域请求的情况下从其他域中发送cookies
            withCredentials: true,//默认为false
            data:datada

          }).then(res => {
            if (res.data.flag==true){
              this.$message.success(res.data.msg)
              this.opens=false
              this.getList()
            }
            if (res.data.flag==!true){
              this.$message.error(res.data.msg)

            }
          });

        // insertLedandSubLed(datada).then(res => {
        //   console.log(res.flag)
        //   if (res.flag == true) {
        //     this.$message({
        //       message: '添加成功',
        //       type: 'success'
        //     })
        //     this.opens = false
        //     this.getList()
        //   }else {
        //     this.$message.error(res.msg);
        //   }
        // })
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        // console.log(row)
        const ids = row.id || this.ids
        this.$confirm('是否确认删除led屏编号为"' + ids + '"的数据项?', '警告', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          // return delLed(ids)
          const api = "http://192.168.10.175:8088/led/delLedAndSub";
          this.$axios({
            url: api,
            method: "get",
            //用于表示用户代理是否在跨域请求的情况下从其他域中发送cookies
            withCredentials: true,//默认为false
            params:{
              id:ids
            }
          }).then(res => {
            if (res.data.flag==true){
              this.$message.success(res.data.msg)
             this.getList()
            }
          });
          // this.msgSuccess('删除成功')
          // this.getList()
        })
      },
      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams
        this.$confirm('是否确认导出所有led屏数据项?', '警告', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(function() {
          return exportLed(queryParams)
        }).then(response => {
          this.download(response.msg)
        }).catch(function() {
        })
      }
    }
  }
</script>
<style lang="less" scoped>
  .el-row {
    position: static !important;
  }
</style>
